﻿function addLink(domid, iskeyword) {
    art.dialog.data('domid', domid);
    art.dialog.open('window_modules.aspx?iskeyword=' + iskeyword, { lock: true, title: '插入链接或关键词', width: 600, height: 400, yesText: '关闭', background: '#000', opacity: 0.45 });
}
function addArticle(domid, iskeyword) {
    art.dialog.data('domid', domid);
    art.dialog.open('window_articles.aspx?iskeyword=' + iskeyword, { lock: true, title: '插入链接或关键词', width: 600, height: 400, yesText: '关闭', background: '#000', opacity: 0.45, close: function () { if (art.dialog.data('aid') != undefined && iskeyword == 1) { updateData(art.dialog.data("aid"), art.dialog.data("atitle"), art.dialog.data("imgurl")) } } });
}
function updateData(id, title, imgurl) {
    var nowIds = $("#hidArticleIds").val();
    if (nowIds.length > 0) {
        var isContain = false;
        var idArr = nowIds.split(",");
        if (idArr.length > 0) {
            $(idArr).each(function (i, item) {
                if (item == id) {
                    isContain = true;
                }
            })
            if (isContain == false) {
                $("#hidArticleIds").val(nowIds + "," + id);
                appendRow(title, imgurl);
            }
        }
    }
    else {
        $("#hidArticleIds").val(id);
        appendFirstRow(title, imgurl);
    }
}
function appendRow(title, imgurl) {
    $(".mediaContent").append("<div class=\"mediaMesg\"><span class=\"mediaMesgDot\"></span><div class=\"mediaMesgTitle left\"><p class=\"left\">" + title + "</p><div class=\"clr\"> </div></div><div class=\"mediaMesgIcon right\"> <img width=\"45\" height=\"45\" src=\"" + imgurl + "\"></div><div class=\"clr\"> </div></div>");
}
function appendFirstRow(title, imgurl) {
    $(".mediaPanel").empty().append("<div class=\"mediaImg\"><div class=\"mediaImgPanel\"> <img width=\"365\" src=\"" + imgurl + "\"></div><div class=\"mediaImgFooter\"><p class=\"mesgTitleTitle left\">" + title + "</p><div class=\"clr\"></div></div></div><div class=\"clr\"> </div><div class=\"mediaContent\"></div>");
}
function delRow(rowId) {
    $("#row" + rowId).remove();
    var nowIds = $("#hidArticleIds").val();
    if (nowIds.length > 0) {
        var tempStr = "";
        var idArr = nowIds.split(",");
        if (idArr.length > 0) {
            $(idArr).each(function (i, item) {
                if (item != rowId) {
                    tempStr += "," + item;
                }
            })
            tempStr = tempStr.substring(1, tempStr.length);
            $("#hidArticleIds").val(tempStr);
        }
    }
}
function delAllRows() {
    $(".mediaPanel").empty();
    $("#hidArticleIds").val("");
}
function validSubmitKeyword() {
    if ($("#ddlMsgType").val() == "news") {
        var nowIds = $("#hidArticleIds").val();
        var idArr = nowIds.split(",");
        if (nowIds == "") {
            alert("请至少选择一篇文章");
            return false;
        }
        if (idArr.length > 10) {
            alert("发送的文章不能超过10篇");
            return false;
        }
    }
}
function validGroupMsg() {
    var nowIds = $("#hidArticleIds").val();
    var idArr = nowIds.split(",");
    if (nowIds == "") {
        alert("请至少选择一篇文章");
        return false;
    }
    if (idArr.length > 10) {
        alert("发送的文章不能超过10篇");
        return false;
    }
    return confirm("确定要群发吗？用户每月只能接受4次群发消息，请谨慎使用");
}